<template>
  <div class="goods-tabs">
    <nav>
      <a @click="activeTab='GoodsDetail'" :class="{active:activeTab==='GoodsDetail'}" href="javascript:;">商品详情</a>
      <a @click="activeTab='GoodsComment'" :class="{active:activeTab==='GoodsComment'}" href="javascript:;">商品评价<span>({{goods.commentCount}})</span></a>
    </nav>
    <!-- 切换内容的地方 其实是两个组件-->
    <!-- <GoodsDetail v-if="activeTab==='GoodsDetail'"></GoodsDetail> -->
    <!-- <GoodsComment v-else></GoodsComment> -->

    <!-- ！！！ -->
    <!-- 在vue中动态切换组件可以使用动态组件component组件 -->
    <!-- is属性用来决定component动态组件渲染为哪个组件，is属性的值为组件名 -->
    <keep-alive>
      <component :is="activeTab"></component>
    </keep-alive>
  </div>
</template>

<script>
import { ref } from '@vue/reactivity'
import GoodsDetail from './goods-detail.vue'
import GoodsComment from './goods-comment.vue'
import { inject } from '@vue/runtime-core'
export default {
  name: 'GoodsTabs',
  components: { GoodsDetail, GoodsComment },
  setup () {
    // activeTab的值GoodsDetail GoodsComment
    const activeTab = ref('GoodsComment')
    const goods = inject('goods')
    return { activeTab, goods }
  }
}
</script>

<style lang="less" scoped>
.goods-tabs{
  min-height: 600px;
  background: #fff;
  nav{
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a{
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      >span{
        color:@priceColor;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child{
      border-right: 1px solid #f5f5f5;
      }
      &.active{
        &::before{
          content: "";
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: @xtxColor;
        }
        // border-bottom: 1px solid @xtxColor;
      }
    }
  }
}
</style>
